﻿package {
	import eventdispatcher.JNEventDispatcher;
	
	import laya.debug.tools.Base64Tool;
	import laya.utils.Browser;
	import laya.webgl.WebGL;
	
	public class LayaSample {
		
		private var URL:String = "http://api.xfyun.cn/v1/service/v1/tts";
		private var AUE:String= "raw";
		private var APPID:String = "5b7bed96";
		private var API_KEY:String = "7c9a9f2712ba001da6295a65056f455f";
		
		public function LayaSample() {
			//初始化引擎
			Laya.init(1136, 640,WebGL);
			GetRequest.sendRequest(URL,getData("测试"),"post","text",getHeader());
			JNEventDispatcher.getInstance().on(JNEventDispatcher.SEND_REQUEST_RESULT,this,listener);
		}		
		private function getHeader():Array{
			var curTime:String = new Date().getTime()+"";
			var param:Object={
				"auf":"audio/L16;rate=16000",
				"aue":"raw",
				"voice_name":"xiaoyan",
				"speed":"50",
				"volume":"50",
				"pitch":"50",
				"engine_type":"intp65",
				"text_type":"text"};
			var paramBase64:String = Base64Tool.encodeStr2(JSON.stringify(param));
			paramBase64="eyJhdWYiOiAiYXVkaW8vTDE2O3JhdGU9MTYwMDAiLCJhdWUiOiAicmF3Iiwidm9pY2VfbmFtZSI6ICJ4aWFveWFuIiwic3BlZWQiOiAiNTAiLCJ2b2x1bWUiOiAiNTAiLCJwaXRjaCI6ICI1MCIsImVuZ2luZV90eXBlIjogImludHA2NSIsInRleHRfdHlwZSI6ICJ0ZXh0In0=";
			var checkSum:String=Browser.window.hex_md5(API_KEY+curTime+paramBase64);
			trace('X-CurTime:',curTime);
			trace('X-Param',paramBase64);
			trace('X-Appid',APPID);
			trace('X-CheckSum',checkSum);
			var header:Array =['X-CurTime',curTime,'X-Param',paramBase64,'X-Appid',APPID,'X-CheckSum',checkSum,'Content-Type','application/x-www-form-urlencoded; charset=utf-8',"Access-Control-Allow-Origin:","*"];
			return header;
		}
		private function getData($str:String):String{
			return encodeURI("text="+$str);
		}
		private function listener(data:Object):void
		{
			// TODO Auto Generated method stub
			
		}
	}
}